import Vue from 'vue';
import Router from 'vue-router';
import guard from './guard';

import index from '@v/index';
import store from '../store';

Vue.use(Router);

// 用于放在meta中的标记
const keepAlive = true; // 带缓存路由
const fromUrlStop = true; //  从URL进入阻止

// 设置路由path和name
// 为什么使用这种模式：合并路由的path和name，确保每个路由必有name。因为从url直接访问一个页面它的route.name必然为null，
// 以此判断是否从url直接进入
function p(name, path) {
	return {
		path: `/${path ? path : name}`,
		name,
		meta: {}, // 防止未设置meta造成取到undefined的情况
	};
}

var routes = [
	{
		path: '/',
		name: 'index',
		component: index,
		meta: { keepAlive, },
	},
	{
		...p('searchPage'),
		component: () => import('@/views/searchPage'),
		meta: { keepAlive, },
	},
	{
		...p('my'),
		component: () => import('@/views/my'),
		meta: { keepAlive, },
	},
	{
		...p('about'),
		component: () => import('@/views/my/about'),
		meta: { keepAlive, },
	},
	{
		...p('problem'),
		component: () => import('@/views/my/problem'),
		meta: { keepAlive, },
	},
	{
		...p('FeedbackRecord'),
		component: () => import('@/views/my/problem/FeedbackRecord'),
		meta: { keepAlive, },
	},
	{
		...p('FeedbackRecordDetails'),
		component: () => import('@/views/my/problem/Details'),
		meta: { keepAlive, },
	},
	{
		...p('address'),
		component: () => import('@/views/my/address'),
		meta: { keepAlive, },
	},
	{
		...p('together'),
		component: () => import('@/views/my/together'),
		meta: { keepAlive, },
	},
	{
		...p('serve'),
		component: () => import('@/views/my/serve'),
		meta: { keepAlive, },
	},
	{
		...p('masterPage'),
		component: () => import('@/views/masterPage'),
		meta: { keepAlive, },
	},
	{
		...p('detailsPage'),
		component: () => import('@/views/detailsPage'),
		meta: { keepAlive, },
	},
	{
		...p('check'),
		component: () => import('@/views/shopDetaPage/check'),
		meta: { keepAlive, },
	},
	{
		...p('scenicSpotMap'),
		component: () => import('@/views/scenicSpotMap'),
		meta: { keepAlive, },
	},
    {
		...p('informationDetails'),
		component: () => import('@/views/scenicSpotMap/informationDetails'),
		meta: { keepAlive, },
	},
	{
		...p('SubmitOrder'),
		component: () => import('@/views/SubmitOrder'),
		meta: { keepAlive, },
	},
	{
		...p('ShoppingCart'),
		component: () => import('@/views/ShoppingCart'),
		meta: { keepAlive, },
	},
	{
		...p('AddAddress'),
		component: () => import('@/views/my/AddAddress'),
		meta: { keepAlive, },
	},
	{
		...p('News'),
		component: () => import('@/views/News'),
		meta: { keepAlive, },
	},
	{
		...p('NewsDetails'),
		component: () => import('@/views/News/Details'),
		meta: { keepAlive, },
	},
	{
		...p('Login'),
		component: () => import('@/views/Login/Login'),
		meta: { keepAlive, },
	},
	{
		...p('Register'),
		component: () => import('@/views/Login/Register'),
		meta: { keepAlive, },
	},
	{
		...p('ForgetPassword'),
		component: () => import('@/views/Login/ForgetPassword'),
		meta: { keepAlive, },
	},
	{
		...p('SetNewPassword'),
		component: () => import('@/views/Login/SetNewPassword'),
		meta: { keepAlive, },
	},
	{
		...p('ChangePassword'),
		component: () => import('@/views/Login/ChangePassword'),
		meta: { keepAlive, },
	},
	// {
	// 	...p('my'), // 这个就相当于同时设置 path: '/my', name: 'my'
	// 	component: () => import('@v/index'), // 路由懒加载
	// },
];

// guard为路由实例添加全局守卫
export default guard(
	new Router({
		mode: 'history',
		base: '', //项目的路由会变成:例子-> localhost:2000/vue/h5/ 再去访问首页
		routes,
	}),
);
